<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="出库单号" prop="issueOrder">
        <el-input
          v-model="queryParams.issueOrder"
          placeholder="请输入出库单号"
          clearable
          maxlength="40"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出库仓库" prop="lssueWarehouse">
        <el-input
          v-model="queryParams.lssueWarehouse"
          placeholder="请输入出库仓库"
          clearable
          maxlength="40"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出库时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="lssueList">
      <el-table-column label="出库单号" align="center" prop="issueOrder"/>
      <el-table-column label="出库金额" align="center" prop="lssueAmount"/>
      <el-table-column label="出库仓库" align="center" prop="lssueWarehouse"/>
      <el-table-column label="出库时间" align="center" prop="lssueTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lssueTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="调拨/销售" align="center" prop="isSaleAllocation" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.erp_sale_allocation" :value="scope.row.isSaleAllocation"/>
        </template>
      </el-table-column>
      <el-table-column label="操作人" align="center" prop="createUser"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="handleInfo(scope.row)"
          >查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listLssue} from "@/api/erp/lssue";

export default {
  name: "Lssue",
  dicts:["erp_sale_allocation"],
  data() {
    return {
      // 日期范围
      dateRange: [],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 出库单表格数据
      lssueList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        issueOrder: null,
        lssueAmount: null,
        lssueWarehouse: null,
        lssueTime: null,
        createUser: null,
        saleId: null
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询出库单列表 */
    getList() {
      this.loading = true;
      listLssue(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.lssueList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查看按钮操作*/
    handleInfo(row) {
      if (row.isSaleAllocation == 0){
        this.$router.push({path: '/InfoLssue', query: {saleId: row.saleId}});
      }
      if (row.isSaleAllocation == 1){
        this.$router.push({path: '/LssueAllocation', query: {id: row.saleId}});
      }
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
      this.dateRange = null;
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('system/lssue/export', {
        ...this.queryParams
      }, `lssue_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
